﻿using System;
using System.Collections.Generic;
using NOSDC.Pocos;
using NOSDC.Repositories;

namespace NOSDC.Services 
{
    public sealed class PollService : IPollService
    {
        private readonly IPollRepository _repository;

        public PollService()
        {
          _repository = new PollRepository();
        }

        public Polls GetLatestPoll()
        {
            return _repository.GetLatestPoll();
        }

        public void SubmitAnswer(PollResults result)
        {
            _repository.SubmitAnswer(result);
        }

        public IList<Polls> GetAllPolls()
        {
            return _repository.GetAllPolls();
        }

        public void CreatePoll(Polls poll)
        {
           _repository.CreatePoll(poll);
        }

        public void UpdatePoll(Polls poll)
        {
            _repository.UpdatePoll(poll);
        }

        public void DeletePoll(Polls poll)
        {
            _repository.DeletePoll(poll);
        }

        /// <summary>
        /// Checks to see if the user has already submitted a response to the poll in question.
        /// </summary>
        /// <param name="userid">user submitting answer</param>
        /// <param name="pollid">the poll the answer belongs too</param>
        /// <returns></returns>
        public bool GetPollResult(Guid userid, int pollid)
        {
            return _repository.GetPollResult(userid, pollid);
        }
    }
}
